package firm;
import java.util.Random;
public class Plurar_Machine {

		private int MachineID;
		private Task task;
		private boolean isRepairing = false;
		private boolean isBroken = false;
		private int left_worker = -1;
		private int right_worker = -1;

		
		public Plurar_Machine(int ID){
			this.MachineID = ID;
		}
		
		public boolean is_Repairing(){
			return isRepairing;
		}
		
		public void Repair(){
			this.isRepairing=false;
		}
		
		public int getID(){
			return MachineID;
		}
		
		public float random(){
			Random r = new Random();
			float result = r.nextFloat();
			return result;
		}
		
		
		public Task start_Machine(Task task, int left_worker, int right_worker){
		
			this.task = task;
			this.left_worker = left_worker;
			this.right_worker = right_worker;
			System.out.println("Plurar machine nr " + MachineID + " starts with thread: " + left_worker + " " + right_worker);
			int x=0, y=0, result=2000000;
			x = task.arg1;
			y = task.arg2;
			task.result = result;
			if(random()<GlobalData.PROBABILITY_OF_BROKE){
				result = x * y;
				task.result = result;
			//System.out.println("Plurar machine nr " + MachineID + " returned: " + task.result);
			}
			else{
				isRepairing = true;
				System.out.println("Plurar machine nr "+ MachineID +" is broken!!! Returning the task...");
			}
			return task;
		}
		
}
